const { Sequelize, DataTypes, Model } = require('sequelize');
const sequelize = new Sequelize('yzq_yqp','root','root',{
    host:'localhost',
    dialect:'mysql',
    dialectOptions:{
        //字符集
        charset:'utf8mb4',
        collate:'utf8mb4_general_ci',
        supportBigNumbers: true,
        bigNumberStrings: true
    },
    pool:{
        max: 5,
        min: 0,
        acquire: 30000,
        idle: 10000
    },
    timezone: '+08:00'  //东八时区
});

try {
    sequelize.authenticate();
    console.log('Connection has been established successfully.');
} catch (error) {
    console.log('Unable to connect to the database:', error)
}
//  检测数据库链接
//测试数据库链接
// sequelize.authenticate().then(function() {
//     console.log("数据库连接成功");
// }).catch(function(err) {
//     //数据库连接失败时打印输出
//     console.error(err);
//     throw err;
// });  
//  try {
//     await sequelize.authenticate();
//     console.log('Connection has been established successfully.');
//   } catch (error) {
//     console.error('Unable to connect to the database:', error);
//   }

module.exports = {
    Sequelize,
    sequelize,
    DataTypes, 
    Model
};